import unittest
import subprocess
import sys
import tempfile
import os

class TestCompatibility(unittest.TestCase):
    """兼容性测试"""
    
    def test_python_version_compatibility(self):
        """测试Python版本兼容性"""
        current_version = sys.version_info
        
        # 验证Python版本 >= 3.7
        self.assertGreaterEqual(current_version.major, 3)
        self.assertGreaterEqual(current_version.minor, 7)
        
        print(f"Running on Python {current_version.major}.{current_version.minor}")
    
    def test_dependency_availability(self):
        """测试依赖项可用性"""
        required_modules = [
            'yaml',      # PyYAML
            'click',     # click
            'jinja2',    # jinja2
            'packaging'  # packaging
        ]
        
        for module in required_modules:
            try:
                __import__(module)
                print(f"✓ {module} available")
            except ImportError:
                self.fail(f"Required module {module} not available")
    
    def test_platform_compatibility(self):
        """测试平台兼容性"""
        import platform
        
        # 应该在Linux平台上运行
        system = platform.system()
        print(f"Running on {system}")
        
        if system != 'Linux':
            print("Warning: splitter is designed for Linux platforms")
    
    def test_file_permission_handling(self):
        """测试文件权限处理"""
        with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
            tmp_path = tmp_file.name
        
        try:
            # 测试读取权限
            os.access(tmp_path, os.R_OK)
            
            # 测试写入权限
            os.access(tmp_path, os.W_OK)
            
            # 测试执行权限（对于目录）
            os.access(os.path.dirname(tmp_path), os.X_OK)
            
        finally:
            os.unlink(tmp_path)